//
//  HHBaseCollectionReusableView.swift
//  ZHUIKit
//
//  Created by Basic on 2019/9/4.
//  UICollectionView - 可复用View
//  title[可选] + detail[可选] + loading[可选]

import UIKit
import BCComConfigKit
import Masonry
import BCUIKit

open class HHBaseCollectionReusableView: UICollectionReusableView {
    //MARK: - property
    /// 是否自定义cell属性，默认NO,使用Base里默认样式
    public var isCustom:Bool = false
    ///标题 label，默认nil，访问属性自动生成
    public var titleLb:UILabel {
        if let view = _titleLb { return view }
        let view = UILabel(frame: CGRect(x: 15, y: 0, width: 0, height: 0))
        view.font = BCComConfig.shared().bcFont()(15)
        view.textColor = BCComConfig.shared().blackColor
        self.addSubview(view)
        view.mas_makeConstraints { (make) in
            make?.left.mas_equalTo()(15)
        }
        _titleLb = view
        return view
    }
    private var _titleLb:UILabel?
    ///描述 label，默认nil，访问属性自动生成
    public var detailLb:UILabel {
        if let view = _detailLb { return view }
        let view = UILabel(frame: CGRect(x: 15, y: 0, width: 0, height: 0))
        view.font = BCComConfig.shared().bcFont()(15)
        view.textColor = BCComConfig.shared().blackColor
        self.addSubview(view)
        view.mas_makeConstraints { (make) in
            make?.right.mas_equalTo()(-15)
        }
        _detailLb = view
        return view
    }
    private var _detailLb:UILabel?
    ///loading 指示器
    public lazy var loadingView:UIActivityIndicatorView = {
        let view = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.white)
        view.color = BCComConfig.shared().defaultColor
        self.addSubview(view)
        return view
    }()
    /// 箭头
    public lazy var arrowButton:UIButton = {
        let button = UIButton.init(type: .custom)
        button.isSelected = false
        button.bc_addTouchUp(insideEvent: {[weak self] (btn) in
            btn.isSelected = !btn.isSelected
            self?._clickBlock?(!btn.isSelected)
        })
        self.addSubview(button)
        button.mas_makeConstraints { (make) in
            make?.edges.mas_equalTo()(UIEdgeInsets())
        }
        return button
    }()
    private var _clickBlock:((_ expand:Bool) ->())?
    /// 设置点击事件
    public func setClickBlock(_ block:((_ expand:Bool) ->())? ) {
        self._clickBlock = block
    }
}
